package com.longteng.java.web;

import com.google.common.collect.Maps;
import com.longteng.java.web.dto.UserInfo;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Created by tianqing.wang
 * DATE : 2018/3/31
 * TIME : 下午11:03
 * PROJECT : web-lesson
 * PACKAGE : com.longteng.java.web
 *
 * @author <a href="mailto:celeskyking@163.com">tianqing.wang</a>
 */
@Component
public class Sender {


    @Resource
    private RestTemplate restTemplate;



    public UserInfo sendGet(){
        String basicURL = "http://localhost:8080/send?user={name}";
        Map<String,String> params = Maps.newHashMap();
        params.put("name","tianqing.wang");
        return restTemplate.getForObject(basicURL, UserInfo.class, params);
    }


    public UserInfo sendPost(UserInfo userInfo) {
        String basicURL = "http://localhost:8080/send";
        return restTemplate.postForObject(basicURL,userInfo,UserInfo.class);
    }

}
